const rules = {
    required: null,
    password: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/,
    email: /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
};

module.exports = (type, value) => {
    let i = 0,
        arr = Object.keys(rules),
        flag = false;
    for (;i < arr.length; i++) {
        if (type === arr[i]) {
            break;
        }
    }
    if (i === arr.length) { // 未找到type
        flag = true;
    } else { // 找到type
        switch (type) {
            case 'required':
                flag = !!value;
                break;
            default:
                flag = rules[type].test(value);
                break;
        }
    }
    return flag;
};